package com.huicoo.forestmanager.util;

/**
 * --------- 日期 ------- 维护人 ------------ 变更内容 --------
 * 2019/4/8		    Administrator
 * 时间格式化工具
 */
public class TimeFormatUtil {

    public static String formatHMS(int seconds) {
        if (seconds <= 0) {
            return "0分0秒";
        }
        //秒
        if (seconds < 60) {
            return String.format("0分%s秒", String.valueOf(seconds));
        }
        //分秒
        if (seconds < 3600) {
            String mm = String.valueOf(seconds / 60);
            String ss = String.valueOf(seconds % 60);
            return String.format("%s分%s秒", mm, ss);
        }
        //时分秒
        if (seconds > 359999) {
            seconds = 359999;
        }
        String hh = String.valueOf(seconds / 3600);
        int modHSeconds = seconds % 3600;
        String mm = String.valueOf(modHSeconds / 60);
        int modMSeconds = modHSeconds % 60;
        String ss = String.valueOf(modMSeconds % 60);
        return String.format("%s小时%s分%s秒", hh, mm, ss);
    }

    public static String formatHMS(float hours) {
        int hour = (int) hours;
        float mins = (hours - hour) * 60;
        int min = (int) mins;
        int second = (int) ((mins - min) * 60);
        int seconds = hour * 3600 + min * 60 + second;
        return formatHMS(seconds);
    }
}
